package cn.itsource.controller.system;




import cn.itsource.annotation.PreAuthorize;
import cn.itsource.service.system.imp.RoleService;
import cn.itsource.system.domain.Role;
import cn.itsource.system.query.RoleQuery;
import cn.itsource.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PreAuthorize(name="查询全部角色",sn="查询全部sn")
    @GetMapping
    public List<Role>  select(){
        return roleService.selectAll();
    }

    @PatchMapping
    public JsonResult deleteMore(@RequestBody Long[] ids){
        try {
            roleService.deleteMore(ids);
            return JsonResult.success("删除用户数据成功！");
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error();
        }
    }


    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Integer id){
        roleService.delete(id);
        return JsonResult.success("删除用户数据成功！");
    }

    @PutMapping
    public JsonResult update(@RequestBody Role role) {
        roleService.update(role);
        return JsonResult.success("修改用户数据成功！");
    }

    @PostMapping
    public PageInfo<Role> queryPage(@RequestBody RoleQuery roleQuery){

        return roleService.queryRole(roleQuery);
    }

















}
